/******************************************************************************
 *
 * @file       main.cpp
 * @brief      信号量
 *             锁的一般化！Lock and unlock multiple resources
 *
 *
 * @author     xiYan
 * @date       2025/06/07
 * @history
 *****************************************************************************/
#include <QCoreApplication>
#include <QSemaphore>
#include <QList>
#include "worker.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QList<int> values;
    for(int i = 0; i< 10;i++)
    {
        values.append(0);
    }

    QSemaphore sema(values.size());
    qInfo() << values;

    QThread thread1;
    QThread thread2;
    thread1.setObjectName("Thread 1");
    thread2.setObjectName("Thread 2");

    Worker worker1(&sema,&values);
    Worker worker2(&sema,&values);
    worker1.moveToThread(&thread1);
    worker2.moveToThread(&thread2);

    QObject::connect(&thread1,&QThread::started,&worker1,&Worker::run);
    QObject::connect(&thread2,&QThread::started,&worker2,&Worker::run);

    thread1.start();
    thread2.start();


    return a.exec();
}
